<?php
/**
 * Created by PhpStorm.
 * User: AaronW
 * Date: 2017/11/22
 * Time: 19:36
 */

namespace App\Api\V1;

use App\Http\Controllers\Controller;
use Dingo\Api\Routing\Helpers;
use Mockery\Exception;

class BaseController extends Controller {
    use Helpers;

    /**
     * @param $errcode
     * @param $msg
     * @param array $data
     * @return \Illuminate\Http\JsonResponse
     */
    public function responseForJson($errcode, $msg = 'ok', $data = []) {
        if (!is_numeric($errcode)  || !is_array($data)) {
            throw new Exception('Parameter type invalid');
        }
        return response()->json([
            'error_code' => $errcode,
            'msg' => $msg,
            'data' => $data
        ]);
    }

}